package com.wbp.cms.web.exception;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.log4j.Logger;
import org.springframework.web.servlet.HandlerExceptionResolver;
import org.springframework.web.servlet.ModelAndView;
/**
 * mvc统一异常处理
 * @author andy.lhc
 *
 */
public class ControllerExceptionResolver implements HandlerExceptionResolver{  //  HandlerExceptionResolverComposite 

	private Logger logger = Logger.getLogger(ControllerExceptionResolver.class) ;
	public ModelAndView resolveException(HttpServletRequest request,
			HttpServletResponse response, Object handler, Exception ex) {
		//System.out.println("==============异常开始=============");
		logger.error("mvc exception:",ex);  // 以后监听日志中的key，监控报警处理
		//System.out.println("==============异常结束=============");
		ModelAndView mv = new ModelAndView("error/500");
		mv.addObject("exception", ex.toString().replaceAll("\n", "<br/>"));
		return mv;
	}

}
